﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xroad.Eu.Xsd.Identifiers;

namespace Xtee.Core.Adapter.Service
{
    public class ServiceNameProvider
    {
        public static string GetName(XRoadServiceIdentifierType xRoadServiceIdentifierType)
        {
            if (xRoadServiceIdentifierType == null)
                return "unavailable";
            
            var sb = new StringBuilder(string.Format("{0}.{1}.{2}", xRoadServiceIdentifierType.XRoadInstance, xRoadServiceIdentifierType.MemberClass, xRoadServiceIdentifierType.MemberCode));

            if (!string.IsNullOrEmpty(xRoadServiceIdentifierType.SubsystemCode))
                sb.Append(string.Format(".{0}", xRoadServiceIdentifierType.SubsystemCode));
            
            sb.Append(string.Format(".{0}", xRoadServiceIdentifierType.ServiceCode));

            if (!string.IsNullOrEmpty(xRoadServiceIdentifierType.ServiceVersion))
                sb.Append(string.Format(".{0}", xRoadServiceIdentifierType.ServiceVersion));
            
            return sb.ToString();
        }

    }
}
